#include "widget.h"
#include "./ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QTimer *time = new QTimer(this);

    connect(ui->pushButton, &QPushButton::clicked, [=](){
        time->start(1000);
    });

    // connect(time, &QTimer::timeout, [=](){
    //     static int num = 1;
    //     ui->label->setText(QString::number(num++));
    // });

    connect(time, &QTimer::timeout, this, &Widget::TimeUpDate);

    connect(ui->pushButton_2, &QPushButton::clicked, [=](){
        time->stop();
    });
}

Widget::~Widget()
{
    delete ui;
}

void Widget::TimeUpDate()
{
    QString str= QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
    ui->label->setText(str);
}
